package com.code.day20;

import java.io.FileInputStream;
import java.io.IOException;

public class DemoFileInputStream02 {

    public static void main(String[] args) throws IOException {
//        method1();
        method2();
    }

    private static void method1() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\2.txt");
        int len = 0;
        while((len =fis.read()) != -1){
            System.out.print((char)len);
            fis.close();

        }

    }

    //逐个字节读取
    private static void method2() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\2.txt");
        byte[] b = new byte[2];
        int len = 0;

        while ((len =fis.read(b)) != -1) {
            System.out.println(new String(b,0,len));
            fis.close();
        }
    }



}
